package profile

import (
	"context"

	"usercenter/internal/biz"
	"usercenter/internal/svc"
	"usercenter/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetJoyImgLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetJoyImgLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetJoyImgLogic {
	return &GetJoyImgLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetJoyImgLogic) GetJoyImg() (resp *types.JoyImgResponse, err error) {
	joyimg, err := l.svcCtx.UserModel.ListJoyImg(1, 40)
	if err != nil {
		return nil, &biz.BizError{
			Code:    500,
			Message: "获取失败",
		}
	}
	var joyimgurl []types.JoyImgURL
	for _, v := range joyimg {
		joyimgurl = append(joyimgurl, types.JoyImgURL{
			JoyID:       v.JoyId,
			JoyImgClass: v.JoyClass,
			JoyImgURL:   v.JoyImgUrl,
			JoyImgCount: v.JoyCount,
		})
	}
	resp = &types.JoyImgResponse{
		Code:    200,
		Message: "success",
		Data:    joyimgurl,
	}
	return resp, nil
}
